#!/usr/bin/env bash
#$ -N mriqc
#$ -o { project_root }/logs
#$ -q { queue }
#$ -j y
#$ -t 1:{ num_jobs }
#$ -tc { max_jobs }

export PROJECT_ROOT={ project_root }
read SUBJECT SESSION <<< $(awk -v id=$SGE_TASK_ID 'NR==id {{print $1, $2}}' { file_sublist })
export SUBJECT SESSION

echo [`date "+%Y-%m-%d %H:%M:%S"`] "Begin mriqc for subject: ${{SUBJECT}}, session: ${{SESSION}}."
{ path_template }/exec_mriqc.sh
echo [`date "+%Y-%m-%d %H:%M:%S"`] "End mriqc for subject: ${{SUBJECT}}, session: ${{SESSION}}."
# clean cache
echo [`date "+%Y-%m-%d %H:%M:%S"`] "Clean temporary files generated by mriqc."
find { path_tmp }/mriqc -depth -name *sub-${{SUBJECT}}*ses-${{SESSION}}* -type d -exec rm -rf {{}} \;
echo [`date "+%Y-%m-%d %H:%M:%S"`] "Clean temporary files generated by mriqc done."
